#include <Kernel/GlobalData.h>
#include <Memory/Paging.h>

/*
@brief 回收物理页框
@param `dwlpPhysicalFrame` 页框物理地址
@return 状态码
*/
DWORD FreeFrame(DWORD_PTR dwlpPhysicalFrame)
{
    dwlpPhysicalFrame -= g_dwlpPrimitiveMemoryPool;
    dwlpPhysicalFrame /= 4096;
    DWORD dwOffset = ReleaseOccupiedBit(dwlpPhysicalFrame, g_bmPrimitiveMemoryPool);
    if (dwOffset == MEMORY_BITMAP_INVALID_OFFSET)
    {
        return FRAME_FREE_UNALLOCATED;
    }
    g_dwMemoryPoolBitmapSearchIndex = (dwOffset + 32) / 32; /* 更新位图查询索引 */
    return FRAME_FREE_SUCCESS;
}